package com.hulk.dryad.common.constant.enums;

import com.google.common.base.Objects;
import lombok.Getter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.EnumSet;

/**
 * @author hulk
 * @see ArchivedFlag 类
 */
public enum DelFlag {

	//未归档
	N("0", "ArchivedFlag_N"),
	//已归档
	Y("1", "ArchivedFlag_Y");

	@Getter
	private String value;

	private String desc;



	public static String explain(String value) {
		for (DelFlag obj : DelFlag.values()) {
			if (Objects.equal(value, obj.value)) {
				return obj.desc;
			}
		}
		return value;
	}

	DelFlag(String value, String desc) {
		this.value = value;
		this.desc = desc;
	}

	public String getDesc() {
		return messageSource.getMessage(desc, null, desc, LocaleContextHolder.getLocale());
	}


	private MessageSource messageSource;

	public DelFlag setMessageSource(MessageSource messageSource) {
		this.messageSource = messageSource;
		return this;
	}

	@Component
	public static class ReportTypeServiceInjector {

		@Resource
		private MessageSource messageSource;

		@PostConstruct
		public void postConstruct() {
			for (DelFlag ec : EnumSet.allOf(DelFlag.class)) {
				ec.setMessageSource(messageSource);
			}
		}
	}
	


}
